﻿@using tour.szhome.common;
@{
    ViewBag.Title = ViewBag.ID != 0 ? "编辑景区" : "添加景区";
}
<h3>@(ViewBag.ID != 0 ? "编辑景区" : "添加景区")</h3>
<div style="padding-left:50px;">
    <hr />
    <table class="tb" style="width:600px;">
        <tbody>
            <tr>
                <td align="center" width="150px"><span>景区名称：</span></td>
                <td><input type="text" id="txtJQMC" value="@Model.JQMC"></td>
            </tr>
            <tr>
                <td align="center"><span>景区描述：</span></td>
                <td><textarea rows="2" cols="20" id="txtJQMS" style="height:70px;width:480px;">@Html.Raw(Model.JQMS)</textarea></td>
            </tr>
            <tr>
                <td align="center"><span>行车路线：</span></td>
                <td><textarea rows="2" cols="20" id="txtXCLX" style="height:70px;width:480px;">@Html.Raw(Model.XCLX)</textarea></td>
            </tr>
            <tr>
                <td align="center"><span>所有项目：</span></td>
                <td><textarea rows="2" cols="20" id="txtSYXM" style="height:40px;width:480px;">@Html.Raw(Model.SYXM)</textarea></td>
            </tr>
            <tr>
                <td align="center"><span>是否推荐：</span></td>
                <td>
                    <table id="radlYesOrNo" border="0" style="width: 100px;">
                        <tbody>
                            <tr>
	                            <td><input id="radYes" type="radio" name="israd" value="1"><label for="radYes">是</label></td>
                                <td><input id="radNo" type="radio" name="israd" value="0" checked="checked"><label for="radNo">否</label></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td align="center"><span>项目类别：</span></td>
                <td>
                    <table id="chklXMLB" border="0" style="height:80px;width:300px;">
                        <tbody>
                            <tr>
	                            <td><input id="ck1" type="checkbox" name="ckbox"><label for="ck1">滨海资源 </label></td>
                                <td><input id="ck2" type="checkbox" name="ckbox"><label for="ck2">湖泊资源</label></td>
                                <td><input id="ck3" type="checkbox" name="ckbox"><label for="ck3">高尔夫资源</label></td>
                            </tr>
                            <tr>
	                            <td><input id="ck4" type="checkbox" name="ckbox"><label for="ck4">温泉资源</label></td>
                                <td><input id="ck5" type="checkbox" name="ckbox"><label for="ck5">山林资源</label></td>
                                <td><input id="ck6" type="checkbox" name="ckbox"><label for="ck6">主题公园资源</label></td>
                            </tr>
                        </tbody>
                    </table>
                </td>                       
            </tr>
        </tbody>
    </table>
    <hr />
    <table class="tb" style="text-align :center;width:600px;">
        <tbody>
            <tr>
                <td>
                    <input type="button" value="@(ViewBag.ID != 0 ? "编辑" : "添加")" id="btnAdd" style="width:60px;">
                    <input type="button" value="返回" id="btnReturn" onclick="javascript: window.history.go(-1);" style="width:60px;">
                </td>
            </tr>
        </tbody>
    </table>
    <hr />
    <table class="tb" style="text-align :center;width:600px;">
        <tbody>
            <tr>
            <td><span>效果图：</span></td>
            <td>
                <img id="imgXGT" src=@(ViewBag.ID > 0 ? ViewBag.uploadAddress + ViewBag.Folder + Model.XGT : CommPath.FileImport("manage/images/zanwutupian.gif")) style="height:100px;width:100px;border-width:0px;">       
                <br>
                （请上传覆盖原有图片。建议大小 100 x 100）<br><br>
                <input type="file" name="upload" id="upload" />
                <input id="ImgV" type="hidden" value="@Model.XGT" />
            </td>
            </tr>
        </tbody>
    </table>
    <hr />
</div>
@CommPath.StyleImport("public/plug-in/uploadify/uploadify.css")
@CommPath.ScriptImport("public/plug-in/uploadify/jquery.uploadify-3.2.js")
<script type="text/javascript">
    $(function () {
        if (@ViewBag.ID > 0) {
            // 页面元素状态绑定
            if("@Model.SFTJ" == "1")
            {
                $("input[name=israd]:eq(0)").attr("checked",'checked')
            }
            else {
                $("input[name=israd]:eq(1)").attr("checked",'checked')
            }
            $("input:checkbox").each(function(){
                if($(this).next().html() == "@Model.XMLB"){
                    $(this).attr("checked","checked");
                }
            })
            $("#dropXMLX option[value='" + "" + "']").attr("selected", "selected");
        }

        //上传图片欲操作
        $('#upload').uploadify({
            'buttonText': '选择文件',
            'buttonClass': 'browser',
            'width': 90,
            'height': 25,
            'formData' : {'f':"@ViewBag.Folder"},
            'fileTypeExts': '*.jpg;*.png;*.bmp;*.gif;',
            'swf': '@CommPath.FileImport("public/plug-in/uploadify/uploadify.swf")',
            'uploader': '/manage/help/UploadFiles',
            'onUploadSuccess': function (file, data, response) {
                $("#imgXGT").attr("src", "@ViewBag.uploadAddress" + "@ViewBag.Folder" + data);
                $("#ImgV").val(data);   //要入库的路径
            },
            'onSelectError': function (file, errorCode, errorMsg) {
                switch (errorCode) {

                    case -110:
                        alert("文件 [" + file.name + "] 大小超出系统限制的" + (1024 * 1024 * 5) + "大小！");
                        break;
                    case -120:
                        alert("文件 [" + file.name + "] 大小异常！");
                        break;
                    case -130:
                        alert("文件 [" + file.name + "] 类型不正确！");
                        break;
                }
            }
        });
    });

    $("#btnAdd").bind("click", function () {
        edit();
    });

    function edit() {
        var txtJQMC = $("#txtJQMC").val();
        var txtJQMS = $("#txtJQMS").val();
        var txtXCLX = $("#txtXCLX").val();
        var txtSYXM = $("#txtSYXM").val();
        var imgXGT = $("#ImgV").val();
        var XMLB = "";
        $("input:checkbox").each(function(){
            if($(this).attr("checked")=="checked"){
                XMLB += $(this).next().html();
            }
        })
        if (XMLB.length > 5) {
            dlg.Msg.Inf("现在只能选择一种项目类别");
            return;
        }

        if (txtJQMC == "") {
            dlg.Msg.Inf("景区名称不能为空");
            return;
        }
        if (txtSYXM == "") {
            dlg.Msg.Inf("所有项目不能为空");
            return;
        }
        $.ajax({
            type: "post",
            url: "/manage/landscape/json_edit",
            data: {
                JQID : @ViewBag.ID,
                JQMC : txtJQMC,
                JQMS : txtJQMS,
                XCLX : txtXCLX,
                SYXM : txtSYXM,
                XGT : imgXGT,
                SFTJ : $('input[name="israd"]:checked').val(),
                XMLB: XMLB
            },
            dataType: "json",
            timeout: 30000, //over time：30s
            beforeSend: function () {
                window.top.qibu.msgbox.loading("正在提交申请，请稍后... ...");
            },
            success: function (data) {
                window.top.qibu.msgbox.hide();
                if (data) {
                    dlg.Msg.Inf("操作成功");
                    setTimeout("window.history.go(-1)", 1000);
                }
                else {
                    dlg.Msg.Err("操作失败");
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                window.top.qibu.msgbox.hide();
                dlg.Msg.Err(errorThrown);
            }
        });
    }
</script>